package com.example.android.services

import com.example.android.extensions.StringBody
import com.example.android.utils.Api
import com.example.android.utils.JsonUtil
import com.example.android.utils.models.MyResult
import java.nio.charset.Charset
import java.util.*
import kotlin.reflect.jvm.internal.impl.protobuf.ByteString

/**
 * @ClassName UpdatePasswordService
 * @Author Ryan Kamanri
 * @Date 2022/6/9
 * @Description
 **/
class UpdatePasswordService(
    private val _Api: Api,
    private val _JsonUtil: JsonUtil
) {
    suspend fun UpdatePassword(account: String, userName: String, userCredit: String, password: String): MyResult<String> {
        val resString = _Api.Post("/user/update-password", {

            it.add("username", Base64.getEncoder().encodeToString(account.encodeToByteArray()))
                .add("name", Base64.getEncoder().encodeToString(userName.toByteArray(Charsets.UTF_8)))
                .add("identity", Base64.getEncoder().encodeToString(userCredit.encodeToByteArray()))
                .add("newPassword", Base64.getEncoder().encodeToString(password.encodeToByteArray()))
        }).StringBody()

        val result = _JsonUtil.FromJsonObject(resString).AsMyResult<String>()

        return result
    }
}